// Playground - noun: a place where people can play

import Foundation

var str = "Hello, playground"

func sum(a: Int)(b: Int) -> Int
{
    return a + b
}

let c = sum(20)
let d = c(b: 20)

protocol TargetAction
{
    func preformAction()
}

enum ControlEvent {
    case TouchUpIndide
    case ValueChanged
}


struct TargetActionWrapper<T: AnyObject> : TargetAction
{
    weak var target : T?
    let action: (T) -> () -> ()
    
    func preformAction() -> ()
    {
        if let t = target {
            action(t)
        }
    }
}

class Control {
    
    var actions = [ControlEvent: TargetAction]()
    func setTarget<T:AnyObject>(target: T, action: (T) -> () -> (), controlEvent: ControlEvent)
    {
        actions[controlEvent] = TargetActionWrapper(target: target, action: action)
    }
    func removeTargetForControlEvent(controlEvent: ControlEvent) {
        actions[controlEvent] = nil;
    }
    func performActionForControlEvent(controlEvent: ControlEvent) {
        actions[controlEvent]?.preformAction()
    }
    
    
}
//test

class MyControl {
    
    let button = Control()
    
    func viewDidLoad()
    {
        button.setTarget(self, action: MyControl.buttonTap, controlEvent: .TouchUpIndide)
        button.performActionForControlEvent(.TouchUpIndide)
    }
    
    func buttonTap()
    {
        println("hello button be tapped")
    }
    
}

let my = MyControl()
my.viewDidLoad()



